package demo1;


public class LeetCode3 {
    public int lengthOfLongestSubstring(String s) {
        // O(n)
        char[] str = s.toCharArray();
        int[] hash = new int[128]; // 用数组模拟哈希表
        int n = s.length() ;
        int len = -1;
        int left = 0 , right = 0;
        while(right < n) {
            hash[str[right]]++;
            while(hash[str[right]] > 1) hash[str[left++]]--;
            len = Math.max(len , right - left + 1);
            right++;
        }
        return len == -1 ? 0 : len;
    }
}
